use strict;
use warnings;
use Test::Simple tests=>14;

# not terribly thorough test of hash operators

BEGIN {
	(-d 'tmp') || mkdir('tmp') || die;
}

# set default path (set for this package only)
use IPC::Lite Path=>'tmp/test.db';

# bind style 1 (shared table, implicit use vars)
use IPC::Lite qw(%a);

# bind style 2 (own table, normal var, tie it up)
our %b;
tie %b, 'IPC::Lite', Table=>'hb';

no strict 'refs';
no warnings 'uninitialized';

# clear other tests
%a = ();
%b = ();

our %x;
# for each style
for (qw(a b)) {
*x = \%$_;
die unless tied(%x);

ok(keys(%x) == 0, "$_ siz 0: " . keys(%x));

$x{a} = 'apple';

ok(keys(%x) == 1, "$_ siz 1: " . keys(%x));
ok($x{a} eq 'apple', "${_}{a} eq apple: " . $x{a});

$x{b}->{m1} = 1;
$x{b}->{n2} = 2;

ok(keys(%x) == 2, "$_ siz 2: " . keys(%x));
ok($x{b}->{m1} eq '1', "${_}{b}->{m1} eq 1: " . $x{b}->{m1});

$x{b}->{m1} = [];
$x{b}->{m1}->[0] = 'hi';
$x{b}->{m1}->[1] = 'ho';
ok($x{b}->{m1}->[0] eq 'hi', "${_}{b}->{m1}->[0] eq 'hi': " . $x{b}->{m1}->[0]);
ok((scalar @{$x{b}->{m1}}) == 2, "\@{\$${_}{b}->{m1}} == 2: " . scalar @{$x{b}->{m1}});

#delete $x{b}->{m1};
#ok(keys(%{$x{b}}) == 1, "$_ siz 1: " . keys(%{$x{b}}));
}
